package com.lmpop.trade.ts_task;

import com.lmpop.frame.QueryList;
import com.lmpop.frame.SysMap;
import com.lmpop.frame.TradeInterf;
import com.lmpop.frame.dao.DbmInterf;
import com.lmpop.frame.exp.ApplicationException;
import java.util.Date;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;

public class Ts_taskInfo implements TradeInterf
{
  QueryList queryList;

  public Ts_taskInfo()
  {
    this.queryList = new QueryList();
  }

  public SysMap insert(DbmInterf dbmMgr, SysMap map)
  {
    String result_code = "0";
    try {
      Ts_task ts_task = new Ts_task();
      ts_task.setTask_id(map.getString("task_id"));
      ts_task.setTask_name(map.getString("task_name"));
      ts_task.setTask_desc(map.getString("task_desc"));
      ts_task.setTask_method(map.getString("task_method"));
      ts_task.setTask_param(map.getString("task_param"));
      ts_task.setIs_exec(map.getString("is_exec"));
      if ((map.getString("start_exec_time") != null) && (!"".equals(map.getString("start_exec_time"))))
        ts_task.setStart_exec_time(map.getString("start_exec_time"));
      else
        ts_task.setStart_exec_time(new Date().toLocaleString());
      ts_task.setOper_userid(map.getString("oper_userid"));
      ts_task.setRemark(map.getString("remark"));
      insert(dbmMgr, ts_task);
    }
    catch (ApplicationException e) {
      e.printStackTrace();
      result_code = "1";
    }
    map.setString("result_code", result_code);
    return map;
  }

  public void insert(DbmInterf dbmMgr, Ts_task ts_task)
    throws ApplicationException
  {
    dbmMgr.update("insertTs_task", ts_task);
  }

  public SysMap delete(DbmInterf dbmMgr, SysMap map)
  {
    String pkid_string = map.getString("pkid");
    String result_code = "0";
    try {
      if (!pkid_string.equals("")) {
        String[] pkStr = pkid_string.split("\\|");
        for (int i = 0; i < pkStr.length; i++) {
          if (pkStr[i].equals("")) continue; delete(dbmMgr, pkStr[i]);
        }
      }
    } catch (ApplicationException e) {
      e.printStackTrace();
      result_code = "1";
    }
    map.setString("result_code", result_code);
    return map;
  }

  public void delete(DbmInterf dbmMgr, String pkid)
    throws ApplicationException
  {
    dbmMgr.update("deleteTs_task", pkid);
  }

  public SysMap update(DbmInterf dbmMgr, SysMap map)
  {
    Ts_task ts_task = new Ts_task();
    ts_task.setTask_id(map.getString("task_id"));
    ts_task.setTask_name(map.getString("task_name"));
    ts_task.setTask_desc(map.getString("task_desc"));
    ts_task.setTask_method(map.getString("task_method"));
    ts_task.setTask_param(map.getString("task_param"));
    ts_task.setIs_exec(map.getString("is_exec"));
    ts_task.setStart_exec_time(map.getString("start_exec_time"));
    ts_task.setOper_userid(map.getString("oper_userid"));
    ts_task.setRemark(map.getString("remark"));
    String result_code = "0";
    try {
      update(dbmMgr, ts_task);
    } catch (ApplicationException e) {
      e.printStackTrace();
      result_code = "1";
    }
    map.setString("result_code", result_code);
    return map;
  }

  public void update(DbmInterf dbmMgr, Ts_task Ts_task) throws ApplicationException
  {
    dbmMgr.update("updateTs_task", Ts_task);
  }

  public List getListByPage(Object obj, int start, int limit)
  {
    Map ts_task = (Hashtable)obj;
    if (start == 0)
      start = 0;
    else {
      start = (start - 1) * limit;
    }
    ts_task.put("start", Integer.valueOf(start));
    ts_task.put("limit", Integer.valueOf(limit));
    return this.queryList.getList("getListByTs_taskPage", ts_task);
  }

  public int getCountByObj(Object obj) {
    Map ts_task = (Hashtable)obj;
    List list = this.queryList.getList("getCountByObjTs_task", ts_task);
    int count = 0;
    if ((list != null) && (list.size() > 0)) {
      Hashtable newsMap = (Hashtable)list.get(0);
      if ((newsMap.get("count") != null) && (!newsMap.get("count").toString().equals(""))) {
        count = Integer.parseInt(newsMap.get("count").toString());
      }
    }
    return count;
  }

  public List getListByPk(String pk)
  {
    return this.queryList.getList("getTs_taskByPk", pk);
  }

  public List getAllTaskList() {
    return this.queryList.getList("getAllTaskList");
  }
}